<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      <a-row>

	<a-col :span="12">
        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['name', validatorRules.name]" placeholder="请输入姓名"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['gender', validatorRules.gender]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =USER_SEX" placeholder="请选择性别"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="年龄" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['age', validatorRules.age]" placeholder="请输入年龄"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择出生日期" v-decorator="['birthday']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="婚姻状况" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['wedlock', validatorRules.wedlock]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =EMP_MARITAL_STATUS" placeholder="请选择婚姻状况"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['nationId']" placeholder="请输入民族"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="籍贯" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['nativePlace']" placeholder="请输入籍贯"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="政治面貌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['politicId']" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =EMP_PARTY" placeholder="请选择政治面貌"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['email', validatorRules.email]" placeholder="请输入邮箱"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['phone', validatorRules.phone]" placeholder="请输入手机"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="本市住址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['address']" placeholder="请输入本市住址"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="所学专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['specialty', validatorRules.specialty]" placeholder="请输入所学专业"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="毕业院校" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['school', validatorRules.school]" placeholder="请输入毕业院校"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['education', validatorRules.education]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = EMP_EDUCATION" placeholder="请选择学历"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="工作经验" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['workExperience']" placeholder="请输入工作经验"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="参加的培训" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['trainingAttend']" rows="4" placeholder="请输入参加的培训"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="所受过的奖励及处分" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['awardPunish']" rows="4" placeholder="请输入所受过的奖励及处分"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="应聘职位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['position', validatorRules.position]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =POSITION" placeholder="请选择应聘职位"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="期望工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['expectedSalary', validatorRules.expectedSalary]" placeholder="请输入期望工资"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="填表日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择填表日期" v-decorator="['writeDate', validatorRules.writeDate]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="上岗时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择上岗时间" v-decorator="['startDate', validatorRules.startDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="其他要求" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['otherRequirements']" placeholder="请输入其他要求"></a-input>
        </a-form-item>
        </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  export default {
    name: "HrCandidateInfoModal",
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          name: {
            rules: [
              { required: true, message: '请输入姓名!'},
            ]
          },
          gender: {
            rules: [
              { required: true, message: '请输入性别!'},
            ]
          },
          age: {
            rules: [
              { required: true, message: '请输入年龄!'},
              { pattern: /^-?\d+$/, message: '请输入整数!'},
            ]
          },
          wedlock: {
            rules: [
              { required: true, message: '请输入婚姻状况!'},
            ]
          },
          email: {
            rules: [
              { required: true, message: '请输入邮箱!'},
            ]
          },
          phone: {
            rules: [
              { required: true, message: '请输入手机!'},
            ]
          },
          specialty: {
            rules: [
              { required: true, message: '请输入所学专业!'},
            ]
          },
          school: {
            rules: [
              { required: true, message: '请输入毕业院校!'},
            ]
          },
          education: {
            rules: [
              { required: true, message: '请输入学历!'},
            ]
          },
          position: {
            rules: [
              { required: true, message: '请输入应聘职位!'},
            ]
          },
          expectedSalary: {
            rules: [
              { required: true, message: '请输入期望工资!'},
            ]
          },
          writeDate: {
            rules: [
              { required: true, message: '请输入填表日期!'},
            ]
          },
          startDate: {
            rules: [
              { required: true, message: '请输入上岗时间!'},
            ]
          },
        },
        url: {
          add: "/online/api/createHrCandidateInfo",
          edit: "/online/api/updateHrCandidateInfo",
          get: "/online/api/getHrCandidateInfo",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        if(record.id){
	      httpAction(this.url.get,{id:record.id},"post").then((res)=>{
	         if(res.success){
		        this.model = Object.assign({}, res.result);
		        this.visible = true;
		        this.$nextTick(() => {
		           this.form.setFieldsValue(pick(this.model,'name','gender','age','birthday','wedlock','nationId','nativePlace','politicId','email','phone','address','specialty','school','education','workExperience','trainingAttend','awardPunish','position','expectedSalary','writeDate','startDate','otherRequirements'))
		        })   
	         }
	      })
        }
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success('提交成功!');
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'name','gender','age','birthday','wedlock','nationId','nativePlace','politicId','email','phone','address','specialty','school','education','workExperience','trainingAttend','awardPunish','position','expectedSalary','writeDate','startDate','otherRequirements'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>
